home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-12  |  8.4 KB  |  336 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. #ifndef NeXT
  17. #include <values.h>
  18. #else
  19. #include <math.h>
  20. #endif
  21. #include "x.h"
  22.  
  23. Cycle_frames()
  24. {
  25.     static int i;
  26.     extern void redraw();
  27.  
  28.     for (i=0;i<=maxframe;i++)
  29.         redraw(indices[i], perind[i], 1); 
  30. }
  31.  
  32. SetFocus(w)
  33. Window w;
  34. {
  35.     extern image_data_t rubber_data;
  36.  
  37.     stacktop = w;
  38.     CreateXorGC(w);
  39.     if (w == trajec) {
  40.         rubber_data.p_min = t_min_x;
  41.         rubber_data.q_min = t_min_y;
  42.         rubber_data.p_max = t_min_x + t_x_range;
  43.         rubber_data.q_max = t_min_y + t_y_range;
  44.     }
  45.     else if (w == crijec) {
  46.         rubber_data.p_min = c_min_x;
  47.         rubber_data.q_min = c_min_y;
  48.         rubber_data.p_max = c_min_x + c_x_range;
  49.         rubber_data.q_max = c_min_y + c_y_range;
  50.     }
  51.     else {
  52.         rubber_data.p_min = min_x;
  53.         rubber_data.q_min = min_y;
  54.         rubber_data.p_max = min_x + x_range;
  55.         rubber_data.q_max = min_y + y_range;
  56.     }
  57. }
  58.  
  59. void
  60. flood(sea, up, old, new) /* sea level change -> sea=1; */
  61. int sea, up, old, new;    /* value increased -> up=1 */
  62. {                        /* old := previous histogram value; ditto new */
  63.     static int i, j, k, diff;
  64.     static double power, ncols;
  65.     extern int **histarray;
  66.     extern int maxhist, minhist, start, cornerbar, updt;
  67.     extern int get_hist_index();
  68.     extern void updtbar();
  69.  
  70.     if (histogram) {
  71.         if (thermometer)
  72.             k = trawidth - THERMWIDTH;
  73.         else
  74.             k = trawidth;
  75.         if ((sea && (!up)) || ((!sea) && up)) {
  76.             /* sea level went down or sky level went up */
  77.             if ((maxhist != 0) && (minhist != MAXINT)) {
  78.                 if (maxhist == minhist)
  79.                     diff = 1;
  80.                 else
  81.                     diff = maxhist - minhist;
  82.             }
  83.             else
  84.                 return;
  85.             ncols = (double)(numcolors - start - 1);
  86.         }
  87.         for (i=0;i<k;i++)        /* redraw only those histogram */
  88.             for (j=0;j<traheight;j++) { /* values that may have changed */
  89.                 if (sea && up) { /* sea level went up */
  90.                     if ((histarray[i][j] < new) && (histarray[i][j] >= old))
  91.                         BufferHisto(i, j, 0);
  92.                 }
  93.                 else if (sea && (!up)) { /* sea level went down */
  94.                     if ((histarray[i][j] >= new) && (histarray[i][j] < old)) {
  95.                         power = (double)(histarray[i][j]-minhist)/(double)diff;
  96.                         BufferHisto(i, j, get_hist_index(power));
  97.                     }
  98.                 }
  99.                 else if ((!sea) && up) { /* sky level went up */
  100.                     if ((histarray[i][j] <= new) && (histarray[i][j] > old)) {
  101.                         power = (double)(histarray[i][j]-minhist)/(double)diff;
  102.                         BufferHisto(i, j, get_hist_index(power));
  103.                     }
  104.                 }
  105.                 else if ((!sea) && (!up)) { /* sky level went down */
  106.                     if ((histarray[i][j] > new) && (histarray[i][j] <= old))
  107.                         BufferHisto(i, j, 0);
  108.                 }
  109.             }
  110.         if (updt) {
  111.           if (showbar == 1) {
  112.             if (portrait && histogram)
  113.               updtbar(hisbar,HISBARHGT,HISBARHGT,cornerbar,maxhist,minhist);
  114.             else
  115.               updtbar(hisbar,HISBARHGT,HISBARHGT,cornerbar,maxperiod,minperiod);
  116.           }
  117.           else if (showbar == 2) {
  118.             if (portrait && histogram)
  119.               updtbar(trajec,traheight/2,traheight,cornerbar,maxhist,minhist);
  120.             else
  121.               updtbar(trajec,traheight/2,traheight,cornerbar,maxperiod,
  122.                             minperiod);
  123.           }
  124.         }
  125.     }
  126. }
  127.  
  128. void
  129. rebasin() 
  130. {
  131.     static int i, j, k, range;
  132.     static int diff[MAXATTRS], maxperiod[MAXATTRS], minperiod[MAXATTRS];
  133.     static double ratio;
  134.     extern int numattrs, first, second, begin, middle, mandel, lowrange;
  135.  
  136.     if (find) {
  137.         range = numfreecols / numattrs;
  138.         for (k=0; k<numattrs; k++)
  139.             maxperiod[k] = 0; minperiod[k] = MAXINT;
  140.         for (i=0;i<perind[frame];i++) {
  141.             k = basins[frame][i];
  142.             j = ABS(periods[frame][i]);
  143.             if (k && j && (j < minperiod[k]))
  144.                 minperiod[k] = j;
  145.             if (k && (j > maxperiod[k]))
  146.                 maxperiod[k] = j;
  147.         }
  148.         for (k=0; k<numattrs; k++)
  149.             diff[k] = maxperiod[k] - minperiod[k];
  150.         for (i=0;i<perind[frame];i++) {
  151.               j = ABS(periods[frame][i]);
  152.               k = basins[frame][i];
  153.               if (j && diff[k]) {
  154.                 ratio=(double)(j - minperiod[k])/(double)diff[k];
  155.                 if (k) {
  156.                     if (precrit == 3) {
  157.                       if (periods[frame][i] > 0)
  158.                         indices[frame][i] = (ratio*(second-1)) + middle;
  159.                       else
  160.                         indices[frame][i] = (ratio*(first-1)) + begin;
  161.                     }
  162.                     else {
  163.                        indices[frame][i]=(ratio*range)+((k-1)*range)+STARTCOLOR;
  164.                     }
  165.                 }
  166.                 else
  167.                     if (mandel == 4)
  168.                         indices[frame][i] = (ratio*(lowrange-1)) + STARTCOLOR;
  169.                     else
  170.                         indices[frame][i] = 0;
  171.               }
  172.         }
  173.    }
  174. }
  175.  
  176. void
  177. rehist() 
  178. {
  179.     static int i, j, k, diff;
  180.     static double power, ncols;
  181.     extern int maxhist, minhist, start;
  182.     extern int **histarray;
  183.     extern int get_hist_index();
  184.  
  185.     if (histogram) {
  186.         if ((maxhist != 0) && (minhist != MAXINT)) {
  187.             if (maxhist == minhist)
  188.                 diff = 1;
  189.             else
  190.                 diff = maxhist - minhist;
  191.             ncols = (double)(numcolors - start - 1);
  192.             if (thermometer)
  193.                 k = trawidth - THERMWIDTH;
  194.             else
  195.                 k = trawidth;
  196.             for (i=0;i<k;i++)
  197.                   for (j=0;j<traheight;j++) {
  198.                     if (histarray[i][j]) {
  199.                           power = (double)(histarray[i][j]-minhist)/(double)diff;
  200.                           BufferHisto(i, j, get_hist_index(power));
  201.                     }
  202.                   }
  203.         }
  204.     }
  205. }
  206.  
  207. void
  208. recalc() 
  209. {
  210.     static int i, j, diff, ncols;
  211.     static double ratio;
  212.     extern int lowrange, first, begin, second, middle;
  213.     extern int start;
  214.     
  215.     if (lyap) {
  216.         for (i=0;i<perind[frame];i++) {
  217.             if (indices[frame][i] < MINCOLINDEX) {
  218.                 ratio=(double)periods[frame][i] / maxexp;
  219.                 indices[frame][i] = ((int)(ratio)%(lowrange-1))+STARTCOLOR;
  220.             }
  221.             else {
  222.                 ratio=(double)periods[frame][i] / (-1.0 * minexp);
  223.                 indices[frame][i]=((int)ratio%(numfreecols-1))+MINCOLINDEX;
  224.             }
  225.         }
  226.     }
  227.     else {
  228.         maxperiod = 0; minperiod = MAXINT;
  229.         for (i=0;i<perind[frame];i++) {
  230.           if ((periods[frame][i] > 0) || (find && (!basins[frame][i]))) {
  231.             if (ABS(periods[frame][i]) < minperiod)
  232.                 minperiod = ABS(periods[frame][i]);
  233.             if (ABS(periods[frame][i]) > maxperiod)
  234.                 maxperiod = ABS(periods[frame][i]);
  235.           }
  236.         }
  237.         diff = maxperiod - minperiod;
  238.         for (i=0;i<perind[frame];i++) {
  239.             if (periods[frame][i] && diff) {
  240.                   ratio=(double)(ABS(periods[frame][i])-minperiod)/(double)diff;
  241.                   if (precrit == 3) {
  242.                     if (periods[frame][i] > 0)
  243.                           indices[frame][i] = (ratio*(second-1)) + middle;
  244.                     else
  245.                       if (basins[frame][i])
  246.                           indices[frame][i] = (ratio*(first-1)) + begin;
  247.                   }
  248.                   else
  249.                     if (periods[frame][i] > 0)
  250.                         indices[frame][i] = (ratio*(second-1)) + middle;
  251.             }
  252.         }
  253.     }
  254. }
  255.  
  256. void
  257. Cleanup() {
  258.     freemem();
  259.     XCloseDisplay(dpy);
  260. }
  261.  
  262. void
  263. Clear(w)
  264. Window w;
  265. {
  266.     static int wid, hei;
  267.     static Pixmap p;
  268.     extern int xmargin, ymargin, axes;
  269.     extern void Draw_Axes();
  270.  
  271.     if (w == canvas) {
  272.         wid = width;
  273.         hei = height;
  274.         p = pixmap;
  275.     }
  276.     else if (w == trajec) {
  277.         if (xmargin && ymargin) {
  278.             wid = trawidth + 1;
  279.             hei = traheight + 1;
  280.         }
  281.         else {
  282.             wid = trawidth;
  283.             hei = traheight;
  284.         }
  285.         p = pixtra;
  286.     }
  287.     else if (w == crijec) {
  288.         wid = criwidth;
  289.         hei = criheight;
  290.         p = pixcri;
  291.     }
  292.     else if (w == prejec) {
  293.         wid = width;
  294.         hei = height;
  295.         p = pixpre;
  296.     }
  297.     else if (w == lyajec) {
  298.         wid = width;
  299.         hei = height;
  300.         p = pixmap;
  301.     }
  302.     else if ((w == info) || (w == help))
  303.         return;
  304.     else {
  305.         perror("Attempt to clear unknown window");
  306.         Cleanup();
  307.         exit(-2);\
  308.     }
  309.     if (thermometer && ((w == trajec) || (w == canvas) || (w == crijec)))
  310.         XFillRectangle(dpy,p,Data_GC[0],xmargin,ymargin,wid-THERMWIDTH,hei);
  311.     else
  312.         XFillRectangle(dpy,p,Data_GC[0],xmargin,ymargin,wid,hei);
  313.     XCopyArea(dpy,p,w,Data_GC[0],xmargin,ymargin,wid,hei,xmargin,ymargin);
  314.     AllInitBuffer();
  315.     if (w == trajec) {
  316.         if (axes)
  317.             Draw_Axes(trajec, 1);
  318.     }
  319. }
  320.  
  321. void
  322. CreateXorGC(w)
  323. Window w;
  324. {
  325.     XGCValues values;
  326.  
  327.     if (RubberGC)
  328.         XFreeGC(dpy, RubberGC);
  329.     values.foreground = foreground;
  330.     values.line_style = LineSolid;
  331.     values.function = GXxor;
  332.     RubberGC = XCreateGC(dpy, DefaultRootWindow(dpy),
  333.           GCForeground | GCBackground | GCFunction | GCLineStyle, &values);
  334. }
  335.  
  336.